# -*- coding:utf-8 -*-
from django import forms

from core.models import Link, Schedule
from core.models import Provider
from core.models import Variable
from core.models import ProxyServer
from core.models import ONCE, EVERY
from core.models import EVERY_HOUR, EVERY_DAY, EVERY_MONTH, EVERY_WEEK, EVERY_YEAR


class LinkForm(forms.ModelForm):
    '''
    def clean_link(self):
        check = URLValidator(verify_exists = True)

        try:
            check(self.cleaned_data['link'])
        except ValidationError as ve:
            #raise forms.ValidationError('Invalid URI')
            print ve

        return self.cleaned_data['link']
    '''

    class Meta:
        model = Link
        widgets = {
            'title': forms.TextInput(attrs = {
                'class': 'field link-title',
                'title': 'Link title',
                'value': 'Link title'
            }),

            'link': forms.TextInput(attrs = {
                'class': 'field link-link',
                'title': 'Resource URI',
                'value': 'Resource URI'
            }),

            'screenshot': forms.CheckboxInput({
                'class': 'field link-screenshot',
                'title': 'Make screenshots?',
                'value': 'Make screenshots?'
            }),

            'dump': forms.CheckboxInput({
                'class': 'field link-dump',
                'title': 'Make dumps?',
                'value': 'Make dumps?',
                'checked': 'checked'
            })
        }

class ProviderForm(forms.ModelForm):
    class Meta:
        model = Provider

        widgets = {
            'name': forms.TextInput(attrs = {
                'class': 'field provider-name',
                'title': 'Provider',
                'value': 'Provider'
            }),

            'ip_range': forms.TextInput(attrs = {
                'class': 'field ip-range',
                'title': 'IP Address',
                'value': 'IP Address'
            })
        }

class ProxyServerForm(forms.ModelForm):
    class Meta:
        model = ProxyServer

        widgets = {
            'host': forms.TextInput(attrs = {
                'class': 'field proxy-host',
                'title': 'Host',
                'value': 'Host'
            }),

            'port': forms.TextInput(attrs = {
                'class': 'field proxy-port',
                'title': 'Port',
                'value': 'Port'
            }),

            'user': forms.TextInput(attrs = {
                'class': 'field proxy-user',
                'title': 'User',
                'value': 'User'
            }),

            'password': forms.TextInput(attrs = {
                'class': 'field proxy-pass',
                'title': 'Password',
                'value': 'Password'
            }),

            'use': forms.CheckboxInput(attrs = {
                'class': 'field proxy-useit',
                'title': 'Port',
                'value': 'Port'
            })
        }

class VariableForm(forms.ModelForm):
    class Meta:
        model = Variable

        widgets = {
            'key': forms.TextInput(attrs = {
                'class': 'field variable',
                'title': 'Name',
                'value': 'Name',
            }),

            'value': forms.TextInput(attrs = {
                'class': 'field variable',
                'title': 'Value',
                'value': 'Value',
            })
        }

class ScheduleForm(forms.ModelForm):
    class Meta:
        model = Schedule

        widgets = {
            'title': forms.TextInput(attrs = {
                'class': 'field title',
                'title': 'Title',
                'value': 'Title',
            }),
            'date_from': forms.DateTimeInput(attrs = {
                'class': 'field date_from',
                'title': 'Select date',
                'value': 'Select date',
            }),
            'date_to': forms.DateTimeInput(attrs = {
                'class': 'field date_to',
                'title': 'Select to',
                'value': 'Select to',
            }),
            'frequency': forms.TextInput(attrs = {
                'class': 'field frequency',
                'title': 'Frequency',
                'value': ONCE,
            }),
            'periods': forms.TextInput(attrs = {
                'class': 'field periods',
                'title': 'Period',
                'value': EVERY_DAY,
            })
        }

class SimpleUpload(forms.Form):
    list = forms.CharField(
        widget = forms.Textarea(attrs = {'class': 'mass-import'}),
        required = False
    )

    file = forms.FileField(widget = forms.FileInput(), required = False)

class ConfirmYesNoForm(forms.Form):
    pass
